package com.smxy.daydayup.util.number;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * @team daydayup
 * @time 2021-12-07 19:08
 */
// 学号解析工具类
public class ResolveNumberUtil {

    public static void main(String[] args) {
        Map map = ResolveNumberUtil.constructMap("20241311001");
        System.out.println(map);
    }

    public static Map constructMap(String userNumber){
        Map<String,String> map = new HashMap<>();
        if(userNumber.length()<4){
            return map;
        }
        map.put("grade", userNumber.substring(0, 4));
        map.put("college", userNumber.substring(4, 6));
        if(userNumber.length()==11) {
            map.put("major", userNumber.substring(6, 8));
            map.put("number", userNumber.substring(8, 9));
            map.put("index", userNumber.substring(9, 11));
        }else if(userNumber.length()==8) {
            map.put("index", userNumber.substring(6, 7));
        }
        return map;
    }

    public static boolean resolveMap(Map<String,String> map){
        if(!checkGrade(map.get("grade"))){
            return false;
        }
        if(!checkNumber(map.get("number"))){
            return false;
        }
        if(!checkIndex(map.get("index"))){
            return false;
        }
        return true;
    }

    private static boolean checkGrade(String record){
        int grade = Integer.parseInt(record);
        Calendar date = Calendar.getInstance();
        String year = String.valueOf(date.get(Calendar.YEAR));
        if(grade<2000 || grade>Integer.parseInt(year)){
            return false;
        }else{
            return true;
        }
    }
    private static boolean checkNumber(String record){
        if("0".equals(record)){
            return false;
        }else{
            return true;
        }
    }
    private static boolean checkIndex(String record){
        if("00".equals(record)){
            return false;
        }else{
            return true;
        }
    }
}
